<?php error_reporting(0);  ?>
<h2>Add New Plan</h2>   
<table id="table" width="900px" cellpadding="5" cellspacing="5">
    <tr>
        <td>
            <?php echo $this->Form->Create('Memberplan'); ?>
            <table cellpadding="10" cellspacing="10">
                <tr>
                    <td id="label" >Title</td>
                    <td><?php echo $this->Form->input('title', array('label' => '', 'size' => '50')); ?></td>
                </tr>  
                <?php $price=explode(',',$this->data['Memberplan']['price']);
                $period=explode(',',$this->data['Memberplan']['period']);
                ?>
                <tr>
                    <td id="label"  >Package prices: </td>
                    <td>
                    
                        <?php echo $this->Form->input('period.0.name', array('label' => 'Period (In Months)', 'size' => '3','value'=>$period['0'])); ?> 
                        <?php echo $this->Form->input('price.0.name', array('label' => 'Price(In $)', 'size' => '3','value'=>$price['0'])); ?></td>
                </tr>
                <tr>
                    <td id="label"  >&nbsp;</td>
                    <td><?php echo $this->Form->input('period.1.name', array('label' => 'Period (In Years)', 'size' => '3', 'limit' => '4','value'=>$period['1'])); ?>
                        <?php echo $this->Form->input('price.1.name', array('label' => 'Price(In $)', 'size' => '3','value'=>$price['1'])); ?>
                      <?php $cnt=2; 
                        for($i=0;count($price)>$i;$i++):
                                if($i>2 and $price!=""){
                                 echo '<br/>'.$this->Form->input('period.'.$cnt.'.name', array('label' => 'Period (In Months)', 'size' => '3','value'=>$period[$i-1])); ?> 
                                <?php echo $this->Form->input('price.'.$cnt.'.name', array('label' => 'Price(In $)', 'size' => '3','value'=>$price[$i-1])); ?>
                        
                        <?php } $cnt++; endfor; ?>
                    </td>
                </tr>
        
                <tr>
                    <td>&nbsp;</td><td> <span id = "addmore"><?php echo $this->Html->image('add.png', array('alt' => 'add more')); ?></span> </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                	<?php echo $this->Form->checkbox('option1', array('label' => '')); ?>You don't need to vote to view U-Ratings and Adjectives for any subject.<br/>
                        <?php echo $this->Form->checkbox('option2', array('label' => '')); ?>See demographic info for the subjects that you enter yourself.<br/>
                        <?php echo $this->Form->checkbox('option3', array('label' => '')); ?>See demographic info without the need of entering in any of your own demographic info.<br/>
                    </td>
                </tr> 
                <tr>
                    <td>&nbsp;</td>
                    <td>
                    	<?php echo $this->Form->input('duration', array('label' => 'Duration(In Days)')); ?>
                        <?php echo $this->Form->input('points', array('label' => 'Points', )); ?>
                    </td>
                </tr> 


                <tr><td></td><td></td></tr>
            </table>
            <?php echo $this->Form->end('Update'); ?>
        </td>
    </tr>
</table>
<script>
    $(document).ready(function(){
           
        $(function(){
            //create a new field then append it before the add field button
            var n=1;
            $("#addmore").click(function(){
                n=n+1;
                var new_field ='<tr class="delete"><td><div class="input text"><label for="period'+n+'Name">Period</label><input name="data[period]['+n+'][name]" type="text" size="3" id="period'+n+'Name" /></div><div class="input text"><label for="price'+n+'Name">Price</label><input name="data[price]['+n+'][name]" type="text" size="3" id="price'+n+'Name" /><img id="delete" alt="add more" src="/focusapp/img/cross.png"></div></td></tr>';
                $(this).before(new_field);
            });
         
        });

   
    });


</script>
